Imports System.Data.SqlClient
Imports System.Data
Partial Class Admin_frmTabSupplier
    Inherits System.Web.UI.Page
    Dim conn As New SqlString()
    Dim _BO As New Bo()
    Dim _SupplierVO As New SupplierVO
    Dim _EmployeeId As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("../Client/frmLogin.aspx")
        End If
        If Not Page.IsPostBack Then
            panel2.Visible = False
            panel4.Visible = False
            GridData()
            CountryData()
            StateData()
            CityData()
        End If
    End Sub
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            _SupplierVO.SupplierId = txtSupplierId.Text
            _SupplierVO.SupplierName = txtSupplierName.Text
            _SupplierVO.Address = txtAddress.Text
            _SupplierVO.Country = ddlCountry.SelectedValue.ToString
            _SupplierVO.State = ddlState.SelectedValue.ToString
            _SupplierVO.City = ddlCity.SelectedValue.ToString
            _SupplierVO.MobileNumber = txtMobileNumber.Text
            _SupplierVO.PhoneNumber = txtPhoneNumber.Text
            _SupplierVO.EmailId = txtEmailId.Text
            _SupplierVO.Zipcode = txtZipcode.Text
            _BO.InsertSupplier(_SupplierVO)
            ClearAll()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub ClearAll()
        txtSupplierId.Text = ""
        txtSupplierName.Text = ""
        txtAddress.Text = ""
        txtZipcode.Text = ""
        txtEmailId.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
        MsgBox("Supplier Inserted")
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _BO.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub
    Sub StateData()
        Dim dtState As DataTable
        dtState = _BO.getstate(ddlCountry.SelectedValue)
        ddlState.DataSource = dtState
        ddlState.DataValueField = dtState.Columns(1).ToString
        ddlState.DataTextField = dtState.Columns(2).ToString
        ddlState.DataBind()
    End Sub
    Sub CityData()
        Dim dtCity As DataTable
        dtCity = _BO.getCity(ddlState.SelectedValue)
        ddlCity.DataSource = dtCity
        ddlCity.DataValueField = dtCity.Columns(2).ToString
        ddlCity.DataTextField = dtCity.Columns(3).ToString
        ddlCity.DataBind()
    End Sub
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        StateData()
        CityData()
    End Sub
    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        CityData()
    End Sub
    Sub GridData()
        Dim dtSupplier As DataTable
        dtSupplier = _BO.getSupplierDetails()
        gdSupplier.DataSource = dtSupplier
        gdSupplier.DataBind()
    End Sub
   
    Protected Sub gdSupplier_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdSupplier.EditCommand
        Session("EmpId") = _EmployeeId
        Response.Redirect("frmModifySupplier.aspx?SupplierId=" & e.Item.Cells(0).Text)
    End Sub
    Protected Sub gdSupplier_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdSupplier.DeleteCommand
        _BO.DeleteSupplier(e.Item.Cells(0).Text)
        Response.Redirect("frmTabSupplier.aspx")
    End Sub
    Protected Sub ImageAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageAdd.Click
        panel2.Visible = True
        panel4.Visible = False
    End Sub

    Protected Sub ImageEdit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageEdit.Click
        panel2.Visible = False
        panel4.Visible = True
        GridData()
    End Sub

    Protected Sub gdSupplier_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles gdSupplier.PageIndexChanged
        gdSupplier.CurrentPageIndex = e.NewPageIndex
        GridData()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtSupplierId.Text = ""
        txtSupplierName.Text = ""
        txtAddress.Text = ""
        txtZipcode.Text = ""
        txtEmailId.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
    End Sub
End Class